﻿@using DTcms.Common;
@{
    ViewBag.Title = "站点管理";
}
<div class="pageheader">
    <div class="page-bar">
        <ul class="page-breadcrumb">
            <li><a href="javascript:;"><i class="iconfont icon-home1"></i> 首页</a> </li>
            <li><a href="javascript:;">站点管理</a> </li>
        </ul>
    </div>
</div>
<div class="layui-fluid">
    <div class="layui-card layui-tab">
        <div class="layui-card-body table-tool-mini">
            <div class="layui-form toolbar">
                <div class="layui-form-item">
                    <div class="menu-list">
                        <div class="layui-inline">
                            <div class="layui-input-inline mr0">
                                <input id="txtKeywords" class="layui-input" type="text" placeholder="输入关键字" />
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn icon-btn layui-btn-normal layui-btn-sm" id="btnSearchAuth" data-type="btnSearch">
                                <i class="layui-icon">&#xe615;</i>搜索
                            </button>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-btn-group">
                            <a data-type="btnAdd" href="../channel/site_edit?action=@DTEnums.ActionEnum.Add" class="layui-btn icon-btn layui-btn-normal layui-btn-sm"><i class="iconfont icon-close1"></i> 新增</a>
                            <a data-type="btnDelete" class="layui-btn icon-btn layui-btn-normal layui-btn-sm"><i class="iconfont icon-delete"></i> 删除</a>
                        </div>
                    </div>
                </div>
            </div>
            <table class="layui-table" lay-data="{page:true, id:'ltable'}" lay-filter="ltable">
                <thead>
                    <tr>
                        <th lay-data="{checkbox:true}"></th>
                        <th lay-data="{field:'title',templet:'#title'}">网站（目录名）</th>
                        <th lay-data="{field:'inherit_id',templet:'#inherit'}">数据源</th>
                        <th lay-data="{field:'domain',templet:'#domain'}">绑定域名</th>
                        <th lay-data="{field:'site_type',templet: '#type'}">网站类型</th>
                        <th lay-data="{field:'sort_id',edit: 'text'}">排序</th>
                        <th lay-data="{field:'is_default',templet: '#switchTpl'}">默认</th>
                        <th lay-data="{templet: '#barDemo'}">操作</th>
                    </tr>
                </thead>
            </table>
        </div>
    </div>
</div>
<script type="text/html" id="title">
    {{d.title + '（'+d.build_path+'）'}}
</script>
<script type="text/html" id="inherit">
    {{d.inherit_id > 0 ? d.inherit : '-'}}
</script>
<script type="text/html" id="domain">
    {{d.domain == '' ? '-' : d.domain}}
</script>
<script type="text/html" id="type">
    {{#
    switch (d.site_type) {
        case "1":
            return "电脑站";
            break;
        case "2":
            return "移动站";
            break;
        case "3":
            return "微信站";
            break;
        default:
            return "未知";
            break;
    }
    }}
</script>
<script type="text/html" id="barDemo">
    <a href="../channel/site_edit?action=@DTEnums.ActionEnum.Edit&id={{d.id}}" class="layui-btn layui-btn-primary layui-btn-xs">修改</a>
</script>
<script type="text/html" id="switchTpl">
    <input type="checkbox" name="is_default" value="{{d.id}}" lay-skin="switch" lay-text="默认|其他" lay-filter="default" {{ d.is_default == 1 ? 'checked' : '' }}>
</script>
@section Scripts{
    <script type="text/javascript">
        layui.use(['cmswh', 'table'], function () {
            var table = layui.table, form = layui.form, cmswh = layui.cmswh, $ = layui.jquery;

            cmswh.dataBind('SiteList');
            //监听单元格编辑
            table.on('edit(ltable)', function (obj) {

                cmswh.request("siteFiledSave", "POST", { field: obj.field, value: obj.value, id: obj.data.id });
            });
            //监听状态操作
            form.on('switch(default)', function (obj) {
                cmswh.request("siteDefault", "POST", { id: this.value, is_default: obj.elem.checked });
            });
            var active = {
                btnDelete: function () {
                    cmswh.batOperate('siteDelete', 'id', '删除该站点将删除对应的目录及文件；<br />如果该站点下还存在频道则无法删除，是否继续？');
                },
                btnSearch: function () {
                    table.reload('ltable', { page: { curr: 1 }, where: getcond() });
                }
            };
            $('.layui-inline .layui-btn').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });

            /*拼接条件返回postdata*/
            function getcond() {
                var keywords = $("#txtKeywords").val();
                var postdata = { keywords: keywords };
                return postdata;
            }
        });
    </script>
}